package com.uzai.console.web.wechatprivate;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.google.common.collect.ImmutableMap;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.wechatprivate.friendrequest.FriendRequestIdListDto;
import com.uzai.console.dto.wechatprivate.friendrequest.FriendRequestQuery;
import com.uzai.console.enums.FriendRequestScene;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.device.DeviceService;
import com.uzai.console.service.wechatprivate.FriendRequestService;
import com.uzai.console.vo.wechatprivate.friendrequest.FriendRequestInfoVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 好友请求
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "个人微信好友请求",tags = "个人微信|好友请求")
@ApiSort(5)
@RestController
public class FriendRequestController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(FriendRequestController.class);

    @Autowired
    private FriendRequestService friendRequestService;
    @Autowired
    private DeviceService deviceService;

    @ApiOperation(value = "查询好友请求列表", notes = "查询好友请求列表", response = FriendRequestInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/friendRequest/findFriendRequestList")
    public Object findFriendRequestList(@RequestBody FriendRequestQuery friendRequestQuery){
        return friendRequestService.findFriendRequestList(friendRequestQuery,true);
    }

    @SystemLogType(model = SystemModelEnum.DeviceWechatFriendRequest, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除好友请求", notes = "删除好友请求", response = Boolean.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/friendRequest/deleteFriendRequest")
    public Object deleteFriendRequest(@RequestBody FriendRequestIdListDto friendRequestIdListDto){
        friendRequestService.deleteFriendRequest(friendRequestIdListDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.DeviceWechatFriendRequest, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "通过好友请求", notes = "通过好友请求" , response = Boolean.class)
    @ApiOperationSupport(order = 3)
    @PostMapping("/friendRequest/addFriendRequest")
    public Object addFriendRequest(@RequestBody FriendRequestIdListDto friendRequestIdListDto){
        friendRequestService.addFriendRequest(friendRequestIdListDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.DeviceWechatFriendRequest, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "忽略好友请求", notes = "忽略好友请求", response = Boolean.class)
    @ApiOperationSupport(order = 4)
    @PostMapping("/friendRequest/passFriendRequest")
    public Object passFriendRequest(@RequestBody FriendRequestIdListDto friendRequestIdListDto) {
        friendRequestService.passFriendRequest(friendRequestIdListDto);
        return true;
    }

    @ApiOperation(value = "好友请求来源", notes = "好友请求来源", response = Boolean.class)
    @PostMapping("/friendRequest/scenes")
    public Object scenes() {
        List<Map<String, Object>> scenes = new ArrayList<>(4);

        scenes.add(ImmutableMap.of("label", FriendRequestScene.PRIVATE_WECHAT_CARD.getLabel(), "value", FriendRequestScene.PRIVATE_WECHAT_CARD.getValue()));
        scenes.add(ImmutableMap.of("label", FriendRequestScene.PRIVATE_WECHAT_GROUP.getLabel(), "value", FriendRequestScene.PRIVATE_WECHAT_GROUP.getValue()));
        scenes.add(ImmutableMap.of("label", FriendRequestScene.PRIVATE_WECHAT_MOBILE.getLabel(), "value", FriendRequestScene.PRIVATE_WECHAT_MOBILE.getValue()));
        scenes.add(ImmutableMap.of("label", FriendRequestScene.PRIVATE_WECHAT_QR_CODE.getLabel(), "value", FriendRequestScene.PRIVATE_WECHAT_QR_CODE.getValue()));
        scenes.add(ImmutableMap.of("label", FriendRequestScene.PRIVATE_WECHAT_SEARCH.getLabel(), "value", FriendRequestScene.PRIVATE_WECHAT_SEARCH.getValue()));
        scenes.add(ImmutableMap.of("label", FriendRequestScene.PRIVATE_WECHAT_QQ.getLabel(), "value", FriendRequestScene.PRIVATE_WECHAT_QQ.getValue()));

        return scenes;
    }
}
